package com.view.judge;

import com.action.listBox.ListComboBoxView;
import com.action.table.JTableMainView;
import com.dao.CoachDao;
import com.dao.JudgeDao;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

public class JudgeUpdate {
    private JFrame jf=null;
    private JButton submit=new JButton("修改"); //查询
    private JLabel nat=new JLabel("属性");
    private JLabel natV=new JLabel("属性的值");
    private JLabel newValue=new JLabel("新的值");
    private JLabel property=new JLabel("要更改的列名");
    private JComboBox nature;   //属性
    private JComboBox natureValue;  //属性值
    private JComboBox properties;  //要更改的属性列
    private JudgeDao jd =new JudgeDao();
    private JTextField jt=new JTextField();
    public JudgeUpdate(){
        jf=new JFrame("教练表查询");
        jf.setLayout(null); //绝对定位
        jf.setSize(430,170);
        nat.setSize(30,30);
        natV.setSize(60,30);
        nat.setLocation(20,20);
        natV.setLocation(160,20);
        property.setSize(80,30);
        property.setLocation(20,60);
        newValue.setSize(50,30);
        newValue.setLocation(20,100);
        ListComboBoxView pritem=new ListComboBoxView(jd.getNations());
        properties=pritem.getJComboBox();
        properties.setSize(100,30);
        properties.setLocation(120,60);
        jt.setSize(150,30);
        jt.setLocation(120,100);
        jf.add(jt);
        jf.add(properties);
        jf.add(newValue);
        jf.add(property);
        jf.add(nat);
        jf.add(natV);

        submit.setSize(60,30);
        submit.setLocation(340,100);
        ListComboBoxView nations =  new ListComboBoxView(jd.getNations());
        ListComboBoxView nationsValue=new ListComboBoxView(jd.nationsV("id"));
        nature=nations.getJComboBox();
        nature.setSize(90,30);
        nature.setLocation(50,20);

        natureValue= nationsValue.getJComboBox();
        natureValue.setSize(150,30);
        natureValue.setLocation(220,20);


        final String[] na = {"id"};
        nature.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                //被选定后
                if(e.getStateChange()==ItemEvent.SELECTED){
                    na[0] =nations.getItem();
                    System.out.println(na.length);
                    System.out.println(na[0]);
                    nationsValue.setNations(jd.nationsV(na[0]));
                }
            }
        });
        submit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(e.getSource()==submit){
                    //查询，展示查询所有的信息
                    jd.updateData(pritem.getItem(),jt.getText(),nations.getItem(),nationsValue.getItem());
                    System.out.println(nations.getItem());
                    System.out.println(nationsValue.getItem());
                    System.out.println(pritem.getItem());
                    System.out.println(jt.getText());
                    new JTableMainView("教练信息", jd.queryData(pritem.getItem(),jt.getText()));
                }
            }
        });


        jf.add(natureValue);
        jf.add(nature);
        jf.add(submit);
        jf.setVisible(true);
    }
}
